﻿// Imports
using System;
using System.Web;
using System.Web.UI;
using System.Web.Routing;
using System.Web.Compilation;

namespace Nickel
{

    /// <summary>
    /// Routes to Default.aspx
    /// </summary>
    public class DefaultRouteHandler : IRouteHandler
    {

        /// <summary>
        /// Get default page
        /// </summary>
        /// <param name="requestContext">Request context</param>
        /// <returns>The web page</returns>
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {

            // Get table name and argument
            string strArgument = requestContext.RouteData.Values[Constants.INPUT_ARGUMENT] as string;
            string strPage = requestContext.RouteData.Values[Constants.INPUT_PAGE] as string;

            // Store the argument and page in the Items collection
            if (!string.IsNullOrEmpty(strArgument)) 
                HttpContext.Current.Items[Constants.INPUT_ARGUMENT] = strArgument;
            if (!string.IsNullOrEmpty(strPage)) 
                HttpContext.Current.Items[Constants.INPUT_PAGE] = strPage;

            // Return page with table and argument
            return BuildManager.CreateInstanceFromVirtualPath(@"~/Pages/Default.aspx", typeof(Page)) as Page;

        }

    }

}
